import com.demo.component.ArticleController;
import com.demo.component.BController;
import com.demo.component.UserComponent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.beans.Introspector;

// 更加简单的将对象存储到Spring中 的测试类 (在Spring 核心项目中, 五大类的注解用法一模一样.)
public class Application {
    public static void main(String[] args) {
        // 1. 先得到 Spring (上下文)对象:
        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");

        // 2. 从 Spring 对象中获取 Bean 对象.                   // 正规的类的默认的 id 是将类名首字母小写之后的类名.
        ArticleController articleController = context.getBean("articleController",ArticleController.class);
                 // 类名首字母和第二个字母大写时, 默认id 就是类名.
        BController bController = context.getBean("BController", BController.class);
        UserComponent userComponent = context.getBean("userComponent", UserComponent.class);

        // 使用 Bean 对象
        System.out.println(articleController.sayHello());
        System.out.println(bController.func());
        System.out.println(userComponent.sayHi());

        System.out.println("--------------------------------------------");
        // 从 Spring 对象中获取 Bean 对象. 类的默认id形式:
        // 1. 正规的类:
        String s1 = "UserInfo";
        System.out.println("s1: " + Introspector.decapitalize(s1));
        // 2. 类名首字母小写:
        String s2 = "userInfo";
        System.out.println("s2: " + Introspector.decapitalize(s2));
        // 3. 类名首字母和第二个字母大写:
        String s3 = "UInfo";
        System.out.println("s3: " + Introspector.decapitalize(s3));
        System.out.println("---------------------------------------------");

        System.out.println(articleController.beanFunc());
        System.out.println(context.getBean("beanFunc"));

    }
}
